<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="Expires" content="0">
		<meta http-equiv="Cache-Control" content="no-cache">
		<meta http-equiv="Pragma" content="no-cache">
		<title>登录华信智原调查网站</title>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
		<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" />
		<style>
			.fa {
				color: red;
			}
			
			p span {
				font-size: 14px;
				font-family: "microsoft yahei";
				color: red;
			}
		</style>
	</head>

	<body>
		<form>
			<p class="xuehao">学号：<input type="text" name="username" placeholder="请输入学号" /><span></span></p>
			<p class="pwd">密码：<input type="password" name="pwd" placeholder="请输入密码" /><span></span></p>
		</form>
		<input type="button" value="登    录" onclick="subLogin();" />

		<script type="text/javascript" src="js/jquery-produce-3.1.0.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="js/bootstrap.min.js" charset="UTF-8"></script>
		<script type="text/javascript" charset="UTF-8">
			$('input[name="username"]').blur(function() {
				if($(".xuehao input[name=username]").val() === "") {
					$(".xuehao").find("span").html("  <i class='fa fa-exclamation'></i> 学号不能为空");
					return false;
				}
				var reg = new RegExp("^[0-9]*$"); //创建一个判断只能为数字的正则表达式并判断
				if($(".xuehao input[name=username]").val().match(reg)) {
					$.ajax({
						type: "post",
						url: "GetUserName",
						async: true,
						data: {
							"username": $("input[name='username']").val()
						},
						dataType: "text",
						success: function(data) {
							if(data == "UserExist") {
								$(".xuehao").find("span").html("  <img src='img/queding.png'/> ");
							} else {
								$(".xuehao").find("span").html("  <img src='img/cuowu.png'/> 用户不存在");
							}
						}
					});
				} else {
					$(".xuehao").find("span").html("  <img src='img/cuowu.png'/> 学号只能为数字");
				}
			});

			$("input[name=pwd]").blur(function() {
				if($(".pwd input[name=pwd]").val() === "") {
					$(".pwd").find("span").html("  <i class='fa fa-exclamation'></i> 密码不能为空");
					return false;
				} else {
					$(".pwd").find("span").html("  <img src='img/queding.png'/> ");
				}
			});

			function subLogin() {
				$.ajax({
					type: "post",
					url: "GetLogin",
					async: true,
					data: $("form").serialize(),
					dataType: "text",
					success: function(data) {
						if(data == "Successful") {
							window.location.href = "survey.html";
						} else {
							$(".pwd").find("span").html("  <img src='img/cuowu.png'/> 密码错误");
						}
					}
				});
			}
		</script>
	</body>

</html>